﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SPStyleCop
{
    public sealed class AnalyzerRegistry
    {
        #region Fields

        private readonly IDictionary<Type, RuleAnalyzerBase> _ruleItems;

        #endregion

        #region Constructor

        /// <summary>
        /// Initializes a new instance of the <see cref="AnalyzerRegistry"/> class.
        /// </summary>
        public AnalyzerRegistry()
        {
            this._ruleItems = new Dictionary<Type, RuleAnalyzerBase>();
        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets the rule analyzers.
        /// </summary>
        /// <value>The rule analyzers.</value>
        public IEnumerable<RuleAnalyzerBase> RuleAnalyzers
        {
            get
            {
                return this._ruleItems.Values ;
            }
        }

        #endregion

        #region Methods

        /// <summary>
        /// Adds a custom rule analyzerBase.
        /// </summary>
        /// <param name="analyzerBase">The rule analyzer.</param>
        public void AddAnalyzer<TRuleItem>(TRuleItem analyzerBase)
                where TRuleItem : RuleAnalyzerBase
        {
            if (!this._ruleItems.ContainsKey(typeof(TRuleItem)))
            {
                this._ruleItems.Add(typeof(TRuleItem), analyzerBase);
            }
        }

        #endregion
    }
}
